package cn.disicn.controller;

import java.util.Date;
import org.apache.commons.lang3.StringUtils;
import cn.disicn.common.Const;
import cn.disicn.common.ServerResponse;
import cn.disicn.model.BizJobsOccupationalScope;
import com.jfinal.core.Controller;

/**
 * @author zjk
 * @date 2018年1月2日 上午9:59:28
 * @desc 职业管理
 */
public class OccupationalScopeController extends Controller {

    private static final BizJobsOccupationalScope occupationalScope = new BizJobsOccupationalScope();

    /**
     * @desc 查询职业
     */
    public void index() {
        Integer pageNum = getParaToInt("pageNum");
        Integer pageSize = getParaToInt("pageSize");
        if (pageNum != null && pageSize != null && pageNum > 0 && pageSize > 0) {
            renderJson(occupationalScope.getOccupationalScopeList(pageNum,
                    pageSize));
            return;
        }
        renderJson(ServerResponse
                .createByErrorMsg(Const.ErrorResult.PARAMETER_ERROR));
    }

    /**
     * @desc 删除职业
     */
    public void delOccupationalScope() {
        String id = getPara("id");
        if (!StringUtils.isBlank(id) && Integer.parseInt(id) != 0) {
            renderJson(occupationalScope.delOccupationalScope(id));
            return;
        }
        renderJson(ServerResponse
                .createByErrorMsg(Const.ErrorResult.PARAMETER_ERROR));
    }

    /**
     * @desc 添加职业
     */
    public void addOccupationalScope() {
        String name = getPara("name");
        if (!StringUtils.isBlank(name)) {
            ServerResponse<String> response = occupationalScope.valiName(name);
            if (response.isSuccess()) {
                occupationalScope.setName(name);
                occupationalScope.setUpdateTime(new Date());
                renderJson(occupationalScope
                        .addOccupationalScope(occupationalScope));
            } else {
                renderJson(response);
            }
            return;
        }
        renderJson(ServerResponse
                .createByErrorMsg(Const.ErrorResult.PARAMETER_ERROR));
    }
}
